package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class LoginPage extends Utils {

    public static String url = "http://49.235.61.184:8080/user/login";

    public LoginPage() {
        super(url);
    }
    /**
     * 注册页面可以正常打开
     */
    public void checkLoginPageRight(){
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.top___1C1Zi > div.header___5xZ3f > span"));
        //检查输入框
        driver.findElement(By.cssSelector("#username"));
        driver.findElement(By.cssSelector("#password"));
        //检查按钮
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button"));
    }
    /**
     * 测试一 登录成功
     */
    public void loginSuc() throws IOException {
        /*//先清空输入框的内容
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();*/
        //刷新
        driver.navigate().refresh();

        //输入正确的账号和密码
        driver.findElement(By.cssSelector("#username")).sendKeys("lin");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button")).click();

        //检测是否登陆成功
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > div > span"));
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
    /**
     * 测试二：输入错误的姓名、密码
     */
    public void loginFile1() throws IOException {
       /* //清空输入框的内容
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();*/
        //刷新
        driver.navigate().refresh();

        //输入错误的姓名、密码
        driver.findElement(By.cssSelector("#username")).sendKeys("hh");
        driver.findElement(By.cssSelector("#password")).sendKeys("aaaaaa");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button")).click();

        //检查是否登录失败
        String str = driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > div.ant-alert.ant-alert-error > div > div")).getText();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str.equals("错误的用户名和密码");
    }
    /**
     * 测试三：输入错误的姓名、正确的密码
     */
    public void loginFile2() throws IOException {
        //刷新
        driver.navigate().refresh();

        //输入错误的姓名、密码
        driver.findElement(By.cssSelector("#username")).sendKeys("aa");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button")).click();

        //检查是否登录失败
        String str = driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > div.ant-alert.ant-alert-error > div > div")).getText();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str.equals("错误的用户名和密码");
    }
    /**
     * 测试四：输入正确的姓名、错误的密码
     */
    public void loginFile3() throws IOException {
        //刷新
        driver.navigate().refresh();

        //输入正确的姓名、错误的密码
        driver.findElement(By.cssSelector("#username")).sendKeys("lin");
        driver.findElement(By.cssSelector("#password")).sendKeys("aaaaaa");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button")).click();

        //检查是否登录失败
        String str = driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > div.ant-alert.ant-alert-error > div > div")).getText();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str.equals("错误的用户名和密码");
    }
    /**
     * 测试五：姓名为空，输入正确的密码
     */
    public void loginFile4() throws IOException, InterruptedException {
        //刷新
        driver.navigate().refresh();

        //姓名为空，输入正确的密码
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button")).click();
        //检查是否登录失败
        Thread.sleep(1000);
        String str = driver.findElement(By.cssSelector("#username_help > div")).getText();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str.equals("用户名是必填项！");
    }
    /**
     * 测试六：密码为空，输入正确的姓名
     */
    public void loginFile5() throws IOException, InterruptedException {
        //刷新
        driver.navigate().refresh();

        //密码为空，输入正确的姓名
        driver.findElement(By.cssSelector("#username")).sendKeys("lin");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button")).click();

        //检查是否登录失败
        Thread.sleep(1000);
        String str = driver.findElement(By.cssSelector("#password_help > div")).getText();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str.equals("密码是必填项！");
    }

}
